<?php
header ( 'Content-Type: text/html; charset=utf-8' );
// Vérification des identifiants
function connexion_site($id, $mdp) {
	global $connexion;
	$requete = 'SELECT * FROM utilisateurs WHERE identifiant = "' . $id . '" AND password = "' . sha1 ( $mdp ) . '";';
	$result = $connexion->query ( $requete );
	$result->setFetchMode ( PDO::FETCH_OBJ );
	if ($result->fetch ())
		return true;
	else
		return false;
	$result->closeCursor ();
}

// Retourne 1 pour admin ou 2 pour développeur
function utilCoTypeC($id) {
	global $connexion;
	$vretour = '';
	$requete = 'SELECT idtype_compte FROM utilisateurs WHERE identifiant = "' . $id . '";';
	$result = $connexion->query ( $requete );
	$result->setFetchMode ( PDO::FETCH_OBJ );
	while ( $data = $result->fetch () ) {
		$vretour = $data->idtype_compte;
	}
	$result->closeCursor ();
	return $vretour;
}
function affiche_tickets_assignés($identifiant) {
	global $connexion;
	$requete = 'SELECT * FROM utilisateurs WHERE identifiant = "' . $identifiant . '";';
	$result = $connexion->query ( $requete );
	$result->setFetchMode ( PDO::FETCH_OBJ );
	if ($result->rowCount () < 1) {
		$corps = 'Connexion impossible';
	} else {
		while ( $OneRow = $result->fetch () ) {
			$requete2 = 'SELECT * FROM appels as a
			INNER JOIN praticiens AS p ON a.idclient = p.id
			INNER JOIN problematique AS pr ON a.idproblematique = pr.id
			INNER JOIN priorite AS prio ON a.idpriorite = prio.id
			INNER JOIN cloturer AS c ON a.idcloturer = c.id
			WHERE idcloturer != 1
			AND prio.id != 4
			AND idtech = ' . $OneRow->id . '
			ORDER BY idpriorite DESC, idcloturer ASC;';
			$result2 = $connexion->query ( $requete2 );
			$result2->setFetchMode ( PDO::FETCH_OBJ );
			if ($result2->rowCount () < 1) {
				$vretour = "Pas de ticket assigné.";
			} else {
				$vretour = '<table class="table table-hover table-striped pagin_it " >
			<thead>
			<tr>
			<th>Client</th>
			<th>Problematique</th>
			<th>Date</th>
			<th>Priorité</th>
			<th>Etat</th>
			</tr>
			</thead><tbody>';
				while ( $OneRow2 = $result2->fetch () ) {
					if ($OneRow2->libelle == "Faible") {
						$class = "success";
					} else if ($OneRow2->libelle == "Moyenne") {
						$class = "warning";
					} else if ($OneRow2->libelle == "Haute") {
						$class = "danger";
					}
					
					$vretour .= '<tr class="' . $class . ' visible">
					<td>' . $OneRow2->nom . "  " . $OneRow2->prenom . '</td>
					<td>' . $OneRow2->nature . '</td>
					<td>' . $OneRow2->dateDebut . '</td>
					<td>' . $OneRow2->libelle . '</td>
					<td>' . $OneRow2->reponse . '</td>
					<td><form action="DetailsAppels.php" id="POST' . $OneRow2->idAppels . '" method="post"><input type="button" class="btn_modifier btn btn-sm btn-primary" value="Modifier"><input type="hidden" class="id" name="modifier" value="' . $OneRow2->idAppels . '"></form> </td>
					<td><input type="button" class="btn btn-sm btn-danger" value="supprimer" onclick="supprimerticket(' . $OneRow2->idAppels . ')"></td>
					</tr>';
					if (strlen ( $OneRow2->commentaires ) < 100) {
						$vretour .= '<tr class="cache">
						<td colspan="7">' . $OneRow2->commentaires . '</td>
						<td><form action="DetailsAppels.php" id="POST' . $OneRow2->idAppels . '" method="post"><a class="fa fa-eye btn_oeil"></a><input type="hidden" class="id" name="modifier" value="' . $OneRow2->idAppels . '"></form> </td>';
					} 

					else {
						$commentaire = str_split ( $OneRow2->commentaires, 100 );
						$vretour .= '<tr class="cache">
						<td colspan="7" class="comreduit">' . $commentaire [0] . '<input type="hidden" class="comComplet" value="' . $OneRow2->commentaires . '"></td>
						<form action="DetailsAppels.php" id="POST' . $OneRow2->idAppels . '" method="post"><td><a class="fa fa-eye btn_oeil"></a><input type="hidden" class="id" name="modifier" value="' . $OneRow2->idAppels . '"></td></form>
								';
					}
					$vretour .= '</tr>';
				}
			}
		}
	}
	$vretour .= '</tbody></table>';
	
	return $vretour;
}
function affiche_tout_tk_fini() {
	global $connexion;
	$requete = 'SELECT * FROM appels as a
			INNER JOIN praticiens AS p ON a.idclient = p.id
			INNER JOIN problematique AS pr ON a.idproblematique = pr.id
			INNER JOIN utilisateurs AS u ON a.idtech = u.id
			WHERE idcloturer = 1';
	$result = $connexion->query ( $requete );
	$result->setFetchMode ( PDO::FETCH_OBJ );
	$vretour = '<table id="example" class="table table-hover table-striped pagin_it" >
			<thead>
			<tr>
				<th>Numéro d\'appel</th>
				<th>Client</th>
				<th>Problématique</th>
				<th>Date</th>
				<th>Technicien affecté</th>
				<th>Lié au ticket</th>
			</tr>
			</thead><tbody>';
	if ($result->rowCount () < 1) {
		$vretour .= '<p>Aucun ticket répertoriés.';
	} else {
		while ( $OneRow = $result->fetch () ) {
			$vretour .= '<tr  class="visible" >
					<td>' . $OneRow->idAppels . '</td>
					<td>' . $OneRow->nom . "  " . $OneRow->prenom . '</td>
					<td>' . $OneRow->nature . '</td>
					<td class="date">' . $OneRow->dateDebut . '</td>
					<td>' . $OneRow->identifiant . '</td>';
			if ($OneRow->idNumTicketLie != 0) {
				$vretour .= '<td>Lié à un ticket</td>';
			} else {
				$vretour .= '<td>Ticket non lié</td>';
			}
			$vretour.='<td><form action="DetailsAppels.php" id="POST' . $OneRow->idAppels . '" method="post"><input type="button" class="btn_modifier btn btn-sm btn-primary" value="Modifier"><input type="hidden" class="id" name="modifier" value="' . $OneRow->idAppels . '"></form> </td>
			</tr>';
			if (strlen ( $OneRow->commentaires ) < 100) {
				$vretour .= '<tr class="cache">
						<td colspan="6">' . $OneRow->commentaires . '</td>
						<td><form action="DetailsAppels.php" id="POST' . $OneRow->idAppels . '" method="post"><a class="fa fa-eye btn_oeil"></a><input type="hidden" class="id" name="modifier" value="' . $OneRow->idAppels . '"></form> </td>';
			} 

			else {
				$commentaire = str_split ( $OneRow->commentaires, 100 );
				$vretour .= '<tr class="cache">
						<td colspan="6" class="comreduit">' . $commentaire [0] . '<input type="hidden" class="comComplet" value="' . $OneRow->commentaires . '"></td>
						<td><form action="DetailsAppels.php" id="POST' . $OneRow->idAppels . '" method="post"><a class="fa fa-eye btn_oeil"></a><input type="hidden" class="id" name="modifier" value="' . $OneRow->idAppels . '"></form> </td>';
			}
			
			$vretour .= '</tr>
							</div>';
		}
	}
	$vretour .= '</tbody></table>';
	return $vretour;
}
function affiche_tout_tk_attente() {
	global $connexion;
	$requete = 'SELECT * FROM problematique';
	$requete2 = 'SELECT * FROM appels as a
			INNER JOIN praticiens AS p ON a.idclient = p.id
			INNER JOIN problematique AS pr ON a.idproblematique = pr.id
			INNER JOIN utilisateurs AS u ON a.idtech = u.id
			INNER JOIN priorite AS prio ON a.idpriorite = prio.id
			INNER JOIN cloturer AS c ON a.idcloturer = c.id
			WHERE idcloturer != 1
			AND idpriorite !=4
			ORDER BY idpriorite DESC, idcloturer ASC';
	$result = $connexion->query ( $requete );
	$result->setFetchMode ( PDO::FETCH_OBJ );
	$result2 = $connexion->query ( $requete2 );
	$result2->setFetchMode ( PDO::FETCH_OBJ );
	if ($result->rowCount () < 1) {
		$vretour .= '<p>Aucun ticket répertorié.';
	} else {
		$vretour = '<table class="table table-hover table-striped pagin_it" >
			<thead>
			<tr >
			<th>Client</th>
			<th>Problematique</th>
			<th>Date</th>
			<th>Technicien</th>
			<th>Priorité</th>
			<th>Etat</th>
			</tr>
			</thead><tbody>';
		while ( $OneRow = $result2->fetch () ) {
			if ($OneRow->libelle == "Faible") {
				$class = "success";
			} else if ($OneRow->libelle == "Moyenne") {
				$class = "warning";
			} else if ($OneRow->libelle == "Haute") {
				$class = "danger";
			}
			$vretour .= '<tr class="' . $class . '  visible">
					<td>' . $OneRow->nom . "  " . $OneRow->prenom . '</td>
					<td>' . $OneRow->nature . '</td>
					<td>' . $OneRow->dateDebut . '</td>
					<td>' . $OneRow->identifiant . '</td>
					<td>' . $OneRow->libelle . '</td>
					<td>' . $OneRow->reponse . '</td>
							<td><form action="DetailsAppels.php" id="POST' . $OneRow->idAppels . '" method="post"><input type="button" class="btn_modifier btn btn-sm btn-primary" value="Modifier"><input type="hidden" class="id" name="modifier" value="' . $OneRow->idAppels . '"></form> </td>
					<td><input type="button" class="btn btn-sm btn-danger" value="supprimer" onclick="supprimerticket(' . $OneRow->idAppels . ')"></td>
					</tr>';
			if (strlen ( $OneRow->commentaires ) < 100) {
				$vretour .= '<tr class="cache">
						<td colspan="7">' . $OneRow->commentaires . '</td>
						';
			} 

			else {
				$commentaire = str_split ( $OneRow->commentaires, 100 );
				$vretour .= '<tr class="cache">
						<td colspan="7" class="comreduit">' . $commentaire [0] . '<input type="hidden" class="comComplet" value="' . $OneRow->commentaires . '"></td>
						
								';
			}
			$vretour .= '<td><form action="DetailsAppels.php" id="POST' . $OneRow->idAppels . '" method="post"><a class="fa fa-eye btn_oeil"></a><input type="hidden" class="id" name="modifier" value="' . $OneRow->idAppels . '"></form> </td>
							
					</tr>';
		}
		$vretour .= '</tbody></table>';
		return $vretour;
		// <input type="submit" value="Modifier"</button></td><input type="hidden" name="modifier" id="' . $OneRow->idAppels . '" value="' . $OneRow->idAppels . '">
	}
}
function retourne_nb_tk_assigne($identifiant) {
	global $connexion;
	$vretour = 0;
	$requete = 'SELECT * FROM utilisateurs WHERE identifiant = "' . $identifiant . '";';
	$result = $connexion->query ( $requete );
	$result->setFetchMode ( PDO::FETCH_OBJ );
	if ($result->rowCount () < 1) {
		$corps = 'Connexion impossible';
	} else {
		while ( $OneRow = $result->fetch () ) {
			$requete2 = 'SELECT * FROM appels as a
			INNER JOIN praticiens AS p ON a.idclient = p.id
			INNER JOIN problematique AS pr ON a.idproblematique = pr.id
			INNER JOIN priorite AS prio ON a.idpriorite = prio.id
			INNER JOIN cloturer AS c ON a.idcloturer = c.id
			WHERE idcloturer != 1
			AND prio.id != 4
			AND idtech = ' . $OneRow->id . '
			ORDER BY idpriorite DESC;';
			$result2 = $connexion->query ( $requete2 );
			$vretour = $result2->rowCount ();
		}
	}
	
	return $vretour;
}
function retourne_nb_tk_non_assigne($identifiant) {
	global $connexion;
	$vretour = 0;
	$requete2 = 'SELECT * FROM appels as a  
			INNER JOIN praticiens AS p ON a.idclient = p.id 
			INNER JOIN problematique AS pr ON a.idproblematique = pr.id
			INNER JOIN utilisateurs AS u ON a.idtech = u.id
			WHERE idcloturer != 1';
	$result2 = $connexion->query ( $requete2 );
	$vretour = $result2->rowCount ();
	return $vretour;
}
function affiche_Categ() {
	$corpsRetour = "";
	global $connexion;
	$requete = 'SELECT * FROM problematique WHERE actif = 1 AND CategPrinc = 0';
	$result = $connexion->query ( $requete );
	$result->setFetchMode ( PDO::FETCH_OBJ );
	$i = 1;
	if ($result->rowCount () < 1) {
		$corpsRetour .= '<select name= "problematique" class="form-control" disable>
				<option> Activer les problématiques</option>';
	} else {
		$corpsRetour .= '<select name= "problematique" id="probPrinc" onchange="afficherSousType()" class="form-control" required>
				<option selected></option>';
		while ( $OneRow = $result->fetch () ) {
			$corpsRetour .= '<option value=' . $OneRow->id . '>' . $OneRow->nature . '</option>';
			$i ++;
		}
	}
	$corpsRetour .= "</select>";
	return $corpsRetour;
}
function affiche_Cloturer() {
	global $connexion;
	$corpsretour = "";
	$requete = 'SELECT * FROM cloturer';
	$result = $connexion->query ( $requete );
	$result->setFetchMode ( PDO::FETCH_OBJ );
	while ( $OneRow = $result->fetch () ) {
		if ($OneRow->id != 0) {
			$corpsretour .= '<option value="' . $OneRow->id . '">' . $OneRow->reponse . '</option>';
		}
	}
	return $corpsretour;
}
function affiche_Priorite() {
	global $connexion;
	$corpsretour = "";
	
	$requete = 'SELECT * FROM priorite WHERE id != 4';
	$result = $connexion->query ( $requete );
	$result->setFetchMode ( PDO::FETCH_OBJ );
	$i = 1;
	while ( $OneRow = $result->fetch () ) {
		$corpsretour .= '<option value=' . $OneRow->id . '>' . $OneRow->libelle . '</option>';
		
		$i ++;
	}
	return $corpsretour;
}
function affiche_Tech() {
	global $connexion;
	$corpsretour = "";
	
	$requete = 'SELECT * FROM utilisateurs';
	$result = $connexion->query ( $requete );
	$result->setFetchMode ( PDO::FETCH_OBJ );
	if ($result->rowCount () < 1) {
		$corpsretour .= '';
	} else {
		while ( $OneRow = $result->fetch () ) {
			if ($_SESSION ['identifiant'] == $OneRow->identifiant) {
				$corpsretour .= '
 					
 					<option selected value=' . $OneRow->id . '>' . $OneRow->identifiant . '</option>';
			} else {
				$corpsretour .= '
 					<option value=' . $OneRow->id . '>' . $OneRow->identifiant . '</option>';
			}
		}
	}
	
	return $corpsretour;
}
function return_Tech_Appeller() {
	global $connexion;
	$corpsretour = "";
	
	$requete = 'SELECT * FROM utilisateurs';
	$result = $connexion->query ( $requete );
	$result->setFetchMode ( PDO::FETCH_OBJ );
	if ($result->rowCount () < 1) {
		$corpsretour .= '';
	} else {
		while ( $OneRow = $result->fetch () ) {
			if ($_SESSION ['identifiant'] == $OneRow->identifiant) {
				$corpsretour = $OneRow->id;
			}
		}
	}
	return $corpsretour;
}
function ajout_Ticket() {
	global $connexion;
	try {
		if (! empty ( $_POST ["commentaire"] ) && ! empty ( $_POST ["problematique"] ) && ! empty ( $_POST ["idClient"] ) && isset ( $_POST ["Cloture"] )) {
			if (! empty ( $_POST ['ticketlie'] )) {
				if ($_POST ['Cloture'] == "1") {
					$priorite = "4";
					echo 'yo';
					if (empty ( $_POST ['problematique2'] )) {
						$commentaire = addslashes ( $_POST ['commentaire'] );
						print_r ( $requete = 'INSERT INTO appels VALUES ( "",' . $_POST ["idClient"] . ',' . $_POST ["problematique"] . ',' . $_POST ["idTechAppel"] . ',"' . $_POST ["datedebut"] . '","' . $_POST ["duree"] . '","' . $commentaire . '","' . $_POST ["idTech"] . '","' . $priorite . '","' . $_POST ["Cloture"] . '","' . $_POST ["ticketlie"] . '")' );
					} else {
						$commentaire = addslashes ( $_POST ['commentaire'] );
						print_r ( $requete = 'INSERT INTO appels VALUES ("" ,' . $_POST ["idClient"] . ',' . $_POST ["problematique2"] . ',' . $_POST ["idTechAppel"] . ',"' . $_POST ["datedebut"] . '","' . $_POST ["duree"] . '","' . $commentaire . '","' . $_POST ["idTech"] . '","' . $priorite . '","' . $_POST ["Cloture"] . '","' . $_POST ["ticketlie"] . '")' );
					}
				} else {
					if (empty ( $_POST ['problematique2'] )) {
						$commentaire = addslashes ( $_POST ['commentaire'] );
						$requete = 'INSERT INTO appels VALUES ( "",' . $_POST ["idClient"] . ',' . $_POST ["problematique"] . ',' . $_POST ["idTechAppel"] . ',"' . $_POST ["datedebut"] . '","' . $_POST ["duree"] . '","' . $commentaire . '","' . $_POST ["idTech"] . '","' . $_POST ["priorite"] . '","' . $_POST ["Cloture"] . '","' . $_POST ["ticketlie"] . '")';
					} else {
						$commentaire = addslashes ( $_POST ['commentaire'] );
						$requete = 'INSERT INTO appels VALUES ("" ,' . $_POST ["idClient"] . ',' . $_POST ["problematique2"] . ',' . $_POST ["idTechAppel"] . ',"' . $_POST ["datedebut"] . '","' . $_POST ["duree"] . '","' . $commentaire . '","' . $_POST ["idTech"] . '","' . $_POST ["priorite"] . '","' . $_POST ["Cloture"] . '","' . $_POST ["ticketlie"] . '")';
					}
				}
			} else {
				if ($_POST ['Cloture'] == "1") {
					$priorite = "4";
					echo 'yo';
					if (empty ( $_POST ['problematique2'] )) {
						$commentaire = addslashes ( $_POST ['commentaire'] );
						$requete = 'INSERT INTO appels VALUES ( "",' . $_POST ["idClient"] . ',' . $_POST ["problematique"] . ',' . $_POST ["idTechAppel"] . ',"' . $_POST ["datedebut"] . '","' . $_POST ["duree"] . '","' . $commentaire . '","' . $_POST ["idTech"] . '","' . $priorite . '","' . $_POST ["Cloture"] . '","0")';
					} else {
						$commentaire = addslashes ( $_POST ['commentaire'] );
						$requete = 'INSERT INTO appels VALUES ("" ,' . $_POST ["idClient"] . ',' . $_POST ["problematique2"] . ',' . $_POST ["idTechAppel"] . ',"' . $_POST ["datedebut"] . '","' . $_POST ["duree"] . '","' . $commentaire . '","' . $_POST ["idTech"] . '","' . $priorite . '","' . $_POST ["Cloture"] . '","0")';
					}
				}else {
					if (empty ( $_POST ['problematique2'] )) {
						$commentaire = addslashes ( $_POST ['commentaire'] );
						$requete = 'INSERT INTO appels VALUES ( "",' . $_POST ["idClient"] . ',' . $_POST ["problematique"] . ',' . $_POST ["idTechAppel"] . ',"' . $_POST ["datedebut"] . '","' . $_POST ["duree"] . '","' . $commentaire . '","' . $_POST ["idTech"] . '","' . $_POST ["priorite"] . '","' . $_POST ["Cloture"] . '","0")';
					} else {
						$commentaire = addslashes ( $_POST ['commentaire'] );
						$requete = 'INSERT INTO appels VALUES ("" ,' . $_POST ["idClient"] . ',' . $_POST ["problematique2"] . ',' . $_POST ["idTechAppel"] . ',"' . $_POST ["datedebut"] . '","' . $_POST ["duree"] . '","' . $commentaire . '","' . $_POST ["idTech"] . '","' . $_POST ["priorite"] . '","' . $_POST ["Cloture"] . '","0")';
					}
				}
			}
			$result = $connexion->query ( $requete );
			$corpsretour = "<strong>Ouh yeah!</strong><br>Nouveau ticket enregistré.";
		} else {
			$corpsretour = "nein";
		}
	} catch ( PDOException $Exception ) {
		$corpsretour = "<strong>Aargg!</strong><br>Ticket pas enregistré..<br>Problème SQL:" . $Exception;
	}
	return $corpsretour;
}
function ajout_Problematique($nature) {
	global $connexion;
	if (1 == 1) {
		$requete3 = 'INSERT INTO problematique VALUES ("", "' . $nature . '",1,0) ;';
		$result3 = $connexion->query ( $requete3 );
		return '<strong>Ouh yeah!</strong><br>Problématique ajoutée avec succès.';
	} else {
		$requete3 = 'INSERT INTO problematique VALUES ("", "' . $_POST ['nomNouvProb'] . '",1,"' . $_POST ['categPrinc'] . '") ;';
		$result3 = $connexion->query ( $requete3 );
	}
}
function ajout_Problematique_secondaire($id, $nature) {
	global $connexion;
	$requete3 = 'INSERT INTO problematique VALUES ("", "' . $nature . '",1,' . $id . ') ;';
	$result3 = $connexion->query ( $requete3 );
	return '<strong>Ouh yeah!</strong><br>Problématique secondaire ajoutée avec succès.';
}
function afficher_tableau_Problematique() {
	global $connexion;
	$pdsec = array ();
	$requete = 'SELECT * FROM problematique ;';
	$result = $connexion->query ( $requete );
	$result->setFetchMode ( PDO::FETCH_OBJ );
	$nature = "";
	$idcateg = "";
	if ($result->rowCount () < 1) {
		echo "pas de problématique";
	} else {
		$vretour = '
		<div class="row">
			<form method="post" name="value" action="gestProblematique.php">
			<input type="hidden" name="post" value="">
				<div class="col-md-6 problematique"> <h2>Problématiques principales</h2>';
		while ( $OneRow = $result->fetch () ) {
			static $i;
			if ($OneRow->CategPrinc == 0) {
				if ($OneRow->actif == 1) {
					$vretour .= '<div id=' . $OneRow->id . '><i class="fa fa-times"></i><span>' . $OneRow->nature . '</span><i class="fa fa-pencil-square-o"></i></div><input type="hidden" name="' . $OneRow->id . '" id="actifBool' . $i . '" value="1">';
				} else {
					$vretour .= '<div id=' . $OneRow->id . '><i class="fa fa-eye"></i><span>' . $OneRow->nature . '</span><i class="fa fa-pencil-square-o"></i></div><input type="hidden" name="' . $OneRow->id . '" id="actifBool' . $i . '" value="1">';
				}
				$requete2 = 'SELECT * FROM problematique WHERE CategPrinc=' . $OneRow->id . ' ;';
				$result2 = $connexion->query ( $requete2 );
				$result2->setFetchMode ( PDO::FETCH_OBJ );
				while ( $OneRow2 = $result2->fetch () ) {
					$i ++;
					if ($OneRow2->actif == 1) {
						array_push ( $pdsec, $OneRow2->nature . '+' . $OneRow2->CategPrinc . '+' . $OneRow2->id . '+fa fa-times' );
					} else {
						array_push ( $pdsec, $OneRow2->nature . '+' . $OneRow2->CategPrinc . '+' . $OneRow2->id . '+fa fa-eye' );
					}
				}
			}
		}
		$vretour .= "</div>";
		$vretour .= '<div class="col-md-6 problematique_secondaire"><h2>Problématiques Secondaires</h2>';
		foreach ( $pdsec as $fetcharray ) {
			list ( $nature, $idcateg, $id, $class ) = explode ( '+', $fetcharray );
			$vretour .= '<div class="categorie_secondaire ' . $idcateg . ' ' . $id . '"><i class="' . $class . '"></i><span>' . $nature . '</span><i class="fa fa-pencil-square-o"></i></div><br>';
		}
		$vretour .= "</div></div>";
	}
	return $vretour;
}
function affiche_ajout_Problematique() {
	global $connexion;
	$requete = 'SELECT * FROM problematique WHERE CategPrinc = 0;';
	$result = $connexion->query ( $requete );
	$result->setFetchMode ( PDO::FETCH_OBJ );
	$corps = '<H1>Ajouter problématique</H2>
			<form method="post" action="gestProblematique.php">
		  <input type="text" name="nomNouvProb"><br>
		  <h3>Problématique Secondaire ? </h3>
		  <input type="radio"  name="princ" value="Oui" onchange="afficherCateg()">Oui <input type="radio" name="princ" onchange="cacherCateg()" value="Non">Non</br>
		  <select name="categPrinc" id="Categ" style="display:none;" >
		  <option selected></option>';
	while ( $OneRow = $result->fetch () ) {
		$corps .= '<option value=' . $OneRow->id . '>' . $OneRow->nature . '</option>';
	}
	$corps .= '</select><input type="submit">
			</form>';
	return $corps;
}
function modif_Problematique($val, $key) {
	global $connexion;
	try {
		$requete3 = 'UPDATE problematique SET nature = "' . $val . '" WHERE id = ' . $key . ' ;';
		$result3 = $connexion->exec ( $requete3 );
		return '<strong>Oh yeah!</strong><br>Le libelle de problématique a été modifié.';
	} catch ( PDOException $e ) {
		return "Probleme dans la requete";
	}
}
function set_invisible($key) {
	global $connexion;
	try {
		$requete3 = 'UPDATE problematique SET actif = 0 WHERE id = ' . $key . ' ;';
		$result3 = $connexion->exec ( $requete3 );
		return '<strong>Disparition!</strong><br>Cette problématique n\'affichera plus.';
	} catch ( PDOException $e ) {
		return "Probleme dans la requete";
	}
}
function set_visible($key) {
	global $connexion;
	try {
		$requete3 = 'UPDATE problematique SET actif = 1 WHERE id = ' . $key . ' ;';
		$result3 = $connexion->exec ( $requete3 );
		return '<strong>Magie!</strong><br>Cette problématique s\'affichera.';
	} catch ( PDOException $e ) {
		return "Probleme dans la requete";
	}
}
function retourne_form_ajout() {
	$format = 'y-m-d  H:i:s';
	$dateDebut = date ( $format );
	return '<div class="row">
			<form action="AjoutTicket.php" method="post" class="col-md-12" name="form_ajout">
				<input type="hidden" name="datedebut" id="datedebut" value="' . $dateDebut . '">
				<input type="hidden" name="type" id="datedebut" value="ajout_tk">
			<div class="form-group col-md-4 col-md-offset-4">
				<label>Rechercher le client:</label>
				<input type="text" autocomplete="off" name="clients2" class="form-control country_id" required onkeyup="autocomplet(this)">
				<input type="hidden" value="" name="idClient" id="idClient">
				<input type="hidden" name="ticketlie" id="ticketlie">			
     			<input type="hidden" name="idTechAppel" value="' . return_Tech_Appeller () . '">
				<div class="country_list_id" class="col-md-12"></div>	
			</div>
			<div class="col-md-6">	
     		<div class="form-group">
     			<label>Assigner ce ticket à :</br></label>
     			<select name ="idTech" class="form-control"required>' . affiche_Tech () . '</select>
			</div>
			<div class="form-group">
				<label>Type d\'intervention :</label>
				' . affiche_Categ () . '
				<select name= "problematique2" id="probSec" class="form-control" style="display:none;">
						<option></option>
				</select>
			</div>
			<div class="form-group">
				<label>Etat du dossier :</label>
				<select name ="Cloture" id ="Cloture" class="form-control" required onchange="disablePriorite()">
				<option selected></option>	' . affiche_Cloturer () . '
				</select>
			</div>
			<div class="form-group">
				<label>Priorité :</label>
				<select name ="priorite" id="prioritedisable" class="form-control">' . affiche_Priorite () . '
				</select>
			</div>
			</div>
			<div class="col-md-6" id="second_row">
				<label >Commentaire :</label>
				<textarea type="textbox" required name="commentaire" class="form-control" rows="5"></textarea>
				<div class="form-group">
					<label>Durée (minute)</label><input type="text" name="duree" required class="form-control">
				</div>
				<input type="button"  class="btn btn-success btn-sm" value="Lier le ticket" onClick="contenumodal()">
			</div>
			<div class="col-md-4 col-md-offset-4">
				<input type="submit" class="btn btn-primary" name="ajout_ticket" value="Enregistrer l\'intervention"/><br>
			</div>';
}
?>